package com.example.bookstore.entity

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonView
import javax.persistence.*

/**
 * Created by IntelliJ IDEA.
 * User: lvshe
 * Date: 2019/8/10
 * Time: 12:50
 */
@Table
@Entity
data class UserEntity(
        @JsonView(UserView::class)
        @Column(nullable = false)
        var nickname: String = "",

        @JsonView(UserView::class)
        @Column(nullable = false, unique = true)
        var email: String = "",

        @Column(nullable = false)
        @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
        var password: String = ""

) : BaseEntity() {

    //    @Fetch(FetchMode.JOIN)
    @JsonIgnoreProperties("user")
    @OneToOne(optional = false, cascade = [CascadeType.ALL])
    @JoinColumn(name = "cart_id", unique = true, nullable = false, updatable = false)
    var cart: CartEntity = CartEntity()

    interface UserView : BaseWithIdView
}